{% extends "djips/common/base.html" %}
{% load djips_extras %}
{% load i18n %}

{% block title %}
{% trans "Manage images" %}
{% endblock %}

{% block externalref %}
    <script type="text/javascript"
            src="{{media_url}}djips/js/jquery.form.js"></script>

    <script type="text/javascript"
            src="{{media_url}}djips/js/admin_images.js"></script>
{% endblock %}


{% block content %}
<div id="update_images_form">
{% if success %}
<p class="info_msg">{% trans "Images have been saved." %}</p>
{% endif %}

{% if errors %}
<p class="error_msg">{% trans "Errors have been found while saving
  your images." %}</p>
{% endif %}

{% if no_sync %}
  <p class="error_msg">{% trans "Please synchronize file system
    before." %}</p>
{% else %}
  {% if values %}
    <form name="update_images"
          {% if current_folder %}
          action="{{admin_base_url}}/djips_common/images/{{current_folder.id}}/"
          {% else%}
          action="{{admin_base_url}}/djips_common/images/"
          {% endif %}
          method="POST">

      <table class="listing"
	     id="update_images_table">
        <thead>
          <tr>
	    <th>{% trans "Image" %}</th>
	    <th>{% trans "Title" %}</th>
	    <th>{% trans "Description" %}</th>
	    <th>{% trans "Mark" %}</th>
	    <th>{% trans "Category" %}</th>
	    <th>{% trans "Tags" %}</th>
	  </tr>
	</thead>
	<tbody>
	  {% for image in values %}
	  <tr class="{% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}">
	    <td>
	      <a href="{{admin_base_url}}/djips_common/image/{{image.id}}">
	      <img src="{{image.thumbnail.url}}"
	      alt="{{image.title}}" />
	      </a>
	    </td>
	    <td>
	      <input type="text"
	      name="title_{{image.id}}"
	      value="{{image.title}}" />
	    </td>
	    <td>
	      <textarea name="description_{{image.id}}">{{image.description}}</textarea>
	    </td>
	    <td>
	      <select name="mark_{{image.id}}">
		{{image.mark|djips_mark_options}}
	      </select>
	    </td>
	    <td>
	      <select name="color_{{image.id}}">
		{{image.color_flag|djips_color_options}}
	      </select>
	    </td>
	    <td>
	      <textarea name="tags_{{image.id}}">{{image.tags_as_list}}</textarea>
	    </td>
	  </tr>
	  {% endfor %}
	</tbody>
      </table>

      <div class="center">
        <input type="submit"
               class="valid"
               name="save"
               value="{% trans "Update images" %}" />
        <input type="submit"
               class="cancel"
               name="cancel"
               value="{% trans "Cancel" %}"/>
      </div>
    </form>
  {% else %}
    <p>{% trans "No images in this folder." %}</p>
  {% endif %}

<div id="update_images_filesystem">
  {{root|djips_filesystem:filesystem_options}}
</div>

{% endif %}
</div>

{% endblock %}
